<template>
  <d2-container>
    <div class="d2-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>运营管理</el-breadcrumb-item>
        <el-breadcrumb-item>Banner管理</el-breadcrumb-item>
        <el-breadcrumb-item>新增Banner</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-form label-width="100px" :model="query" ref="add" :rules="rules">
      <el-form-item label="排列序号" prop="sort" :rules="[
      { required: true, message: '字段不能为空'}
    ]">
        <el-input v-model="query.sort" style="width: 220px"></el-input>
      </el-form-item>
      <el-form-item label="跳转链接" prop="addressUrl">
        <el-input v-model="query.addressUrl" style="width: 220px"></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="query.type" placeholder="请选择">
          <el-option label="园区" :value="0"></el-option>
          <el-option label="园区企业" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="query.status" placeholder="请选择">
          <el-option label="上架" :value="0"></el-option>
          <el-option label="下架" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="下架时间" prop="offTime">
        <el-date-picker
          v-model="query.offTime"
          type="datetime"
          placeholder="选择日期时间"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="图片">
        <img-upload
          tip="建议:图片小于1M"
          v-model="query._imageUrl"
          :limit="1"
          listType="picture-card"
        ></img-upload>
      </el-form-item>
      <el-form-item v-loading="loading">
        <el-button type="primary" @click="add">新增</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>
<script>
export default {
  name: "AddCloudAccount",
  data() {
    return {
      loading: false,
      query: {},
      rules: {},
    };
  },
  methods: {
    add() {
      this.$refs["add"].validate((val) => {
        if (val) {
          let params = {
            ...this.query,
          };
          if (params.offTime) {
        params.offTime = new Date(
          Date.parse(new Date(params.offTime)) + 8 * 3600 * 1000
        );
      }
          if (this.query._imageUrl && this.query._imageUrl.length > 0) {
            params.imageUrl = this.query._imageUrl[0].url;
          }

          this.$axios.post("/sysBannerUrl/add", params).then((res) => {
            if (res.code) {
              this.$message.success("操作成功");
              this.$router.push("/operation");
            } else {
              this.$message.error(res.data.msg);
            }
          });
        } else {
          this.$message.error("请确认表单信息无误");
          return false;
        }
      });
    },
  },
  created() {},
};
</script>